package com.wl.eduorder.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wl.connonutils.JwtUtils;
import com.wl.connonutils.R;
import com.wl.eduorder.client.CourseClient;
import com.wl.eduorder.client.MemberClient;
import com.wl.eduorder.entity.Order;
import com.wl.eduorder.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 订单 前端控制器
 * </p>
 *
 * @author wl
 * @since 2021-09-06
 */
@RestController
@RequestMapping("/eduorder/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("createOrder/{courseId}")
    public R createOrder(@PathVariable("courseId") String id, HttpServletRequest request){
        String orderNo = orderService.createOrders(id,JwtUtils.getMemberIdByJwtToken(request));
        return R.ok().data("orderId",orderNo);
    }

    @GetMapping("getOrderInfo/{orderId}")
    public R getOrderInfo(@PathVariable("orderId")String orderId){
        QueryWrapper<Order> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(Order::getOrderNo,orderId);
        Order one = orderService.getOne(wrapper);
        return R.ok().data("item",one);
    }

}

